package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.OrderDetail;
import com.ruoyi.business.service.IOrderDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单详情Controller
 * 
 * @author liwenjing
 * @date 2021-05-15
 */
@RestController
@RequestMapping("/business/orderDetail")
public class OrderDetailController extends BaseController
{
    @Autowired
    private IOrderDetailService orderDetailService;

    /**
     * 查询订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderDetail orderDetail)
    {
        startPage();
        List<OrderDetail> list = orderDetailService.selectOrderDetailList(orderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:export')")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderDetail orderDetail)
    {
        List<OrderDetail> list = orderDetailService.selectOrderDetailList(orderDetail);
        ExcelUtil<OrderDetail> util = new ExcelUtil<OrderDetail>(OrderDetail.class);
        return util.exportExcel(list, "orderDetail");
    }

    /**
     * 获取订单详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:orderDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderDetailService.selectOrderDetailById(id));
    }

    /**
     * 新增订单详情
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderDetail orderDetail)
    {
        return toAjax(orderDetailService.insertOrderDetail(orderDetail));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderDetail orderDetail)
    {
        return toAjax(orderDetailService.updateOrderDetail(orderDetail));
    }

    /**
     * 删除订单详情
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderDetailService.deleteOrderDetailByIds(ids));
    }

    /**
     * 评价
     * @author liwenjing
     * @date 2021/5/17
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:score')")
    @Log(title = "写评价",businessType = BusinessType.OTHER)
    @PutMapping(value="/score")
    public AjaxResult score(@RequestBody OrderDetail orderDetail)
    {
        return toAjax(orderDetailService.updateOrderDetail(orderDetail));
    }

    /**
     * 确认完成服务
     * @date 2021/5/25
     * 确认完成服务，更改订单状态
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:ok')")
    @Log(title = "确认完成服务",businessType = BusinessType.OTHER)
    @PutMapping(value="/ok")
    public AjaxResult ok(@RequestBody Long id){
        return toAjax(orderDetailService.ok(id));
    }

    /**
     * 申请退款
     * @date 2021/5/25
     * 申请退款，更改订单状态
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:cancel')")
    @Log(title = "申请退款",businessType = BusinessType.OTHER)
    @PutMapping(value="/cancel")
    public AjaxResult cancelOrderDetail(@RequestBody Long id){
        return toAjax(orderDetailService.cancelOrderDetail(id));
    }

    /**
     * 同意退款申请
     * @date 2021/5/25
     * 同意退款申请，更改订单状态
     */
    @PreAuthorize("@ss.hasPermi('business:orderDetail:green')")
    @Log(title = "同意申请退款",businessType = BusinessType.OTHER)
    @PutMapping(value="/green")
    public AjaxResult greenOrderDetail(@RequestBody Long id){
        return toAjax(orderDetailService.greenOrderDetail(id));
    }
}
